﻿/****************************** Module Header ******************************\
 * Module Name:  HiddenFieldLiteral.cs
 * Module Version:  1.0.0 (2012-9-17)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used for HiddenFieldLiteral.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System.Collections.Generic;
using System.Text;

namespace UCF.Core.Web
{
    public class HiddenFieldLiteral
    {
        private Dictionary<string, object> dict = new Dictionary<string, object>();
        private static HiddenFieldLiteral instance;
        public static HiddenFieldLiteral New()
        {
            if (instance == null) instance = new HiddenFieldLiteral();
            return instance;
        }
        public HiddenFieldLiteral() { }
        public HiddenFieldLiteral(Dictionary<string, object> items) { this.dict = items; }
        public HiddenFieldLiteral Add(string name,object value){
            dict.Add(name, value);
            return instance;
        }

        /// <summary>
        /// 输出控件字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach (string k in dict.Keys)
            {
                sb.AppendLine("<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />".Fmt(k, dict[k]));
            }
            instance = null;
            return sb.ToString();
        }
    }
}
